const path = require('path');
const util = require('util');
const fs = require('fs');

var urlReg = /url\s*\(\s*['|"]?([^'")]+)['|"]?\s*\)/gim;

console.log('NODE_ENV: '+process.env.NODE_ENV);
console.log('cwd: '+process.cwd());
console.log('platform: '+process.platform);  //win 32
console.log('sep: '+path.sep); //\

let obj = {
    name: 'katy',
    test: function(){
        console.log('hello world');
    }
}

console.log(util.inspect(obj));

// nodejs 转换普通图片为 base64

let file = fs.readFileSync(path.resolve(__dirname,'event.js'));  //读出来的是 Buffer
console.log(file);

let smilePath = path.resolve(__dirname,'../src/smile.jpg');
let smile = fs.readFileSync(smilePath);
let stat = fs.statSync(smilePath); //单位为b   11.6kb * 1024
let str = smile.toString('base64');
let ext = path.extname(smilePath);
console.log(stat);
console.log(`ext: ${ext}`);  //.jpg
console.log(stat.constructor);  //stats
// console.log(str);

// SVG嵌入页面 咋整
var sourceUrl = 'url(./src/smile.jpg)';
sourceUrl.replace(urlReg, function(match, url){
    console.log(match);
    console.log(url);
});
